package week6;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main1
{
	public static void main(String[] args) 
	{
		Scanner in = new Scanner(System.in);
		List<Person> personList = new ArrayList<Person>();
		List<Student> stuList = new ArrayList<Student>();
		List<Employee> empList = new ArrayList<Employee>();
		int a=0;
		while (in.hasNext()) 
		{
			String choice = in.next();
			switch (choice) 
			{
				case "s":
					Student stu = new Student(in.next(),in.nextInt(),in.nextBoolean(),in.next(),in.next());
					personList.add(stu);
					break;
				case "e":
					Employee emp = new Employee(in.next(),in.nextInt(),in.nextBoolean(),in.nextDouble(),new Company(in.next()));
					personList.add(emp);
					break;
				default:
					a=1;
					break;
			}
			if(a==1)
				break;
		}
		Collections.sort(personList);
		if( in.next().equals("exit"))
			return;
		else
		{
			for (int i = 0; i < personList.size(); i++) 
			{
				System.out.println(personList.get(i));
			}
			for (int i = 0; i < personList.size(); i++) 
			{
				int b=0;
				if (personList.get(i).getClass().equals(Employee.class))
				{
					for (int j = 0; j <empList.size(); j++) 
					{
						if(empList.get(j).equals(personList.get(i)))
							b=1;
					}
					if(b==0)
						empList.add((Employee)personList.get(i));	
				}
				else
				{
					for (int j = 0; j < stuList.size(); j++) 
					{
						if(stuList.get(j).equals(personList.get(i)))
							b=1;
					}
					if(b==0)
						stuList.add((Student)personList.get(i));
				}
			}
			System.out.println("stuList");
			for (int i = 0; i < stuList.size(); i++) 
			{
				System.out.println(stuList.get(i));
			}
			System.out.println("empList");
			for (int i = 0; i < empList.size(); i++) 
			{
				System.out.println(empList.get(i));
			}
		}
	}
}

abstract class Person implements Comparable<Person>
{
	private String name;
	private int age;
	private boolean gender;

	public Person(String name, int age, boolean gender) 
	{
		if (name == null)
			this.name=null;
		else
			this.name = name;
		this.age = age;
		this.gender = gender;
	}
	@Override
	public String toString() 
	{
		return name+"-"+age+"-"+gender;
	}
	@Override
	public boolean equals(Object obj) 
	{
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Person other = (Person) obj;
		if (age == other.age && gender == other.gender && name.equals(other.name))
			return true;
		return false;
	}
	@Override
	public int compareTo(Person o) 
	{
		if(!name.equals(o.name))
			return name.compareTo(o.name);
		return age-o.age;
	}
}

class Student extends Person
{
	private String stuNo;
	private String clazz;
	public Student(String name, int age, boolean gender, String stuNo, String clazz) 
	{
		super(name, age, gender);
		if (stuNo == null)
			this.stuNo=null;
		else
			this.stuNo = stuNo;
		if (clazz == null)
			this.clazz=null;
		else
			this.clazz = clazz;
	}
	@Override
	public String toString() 
	{
		return "Student:"+super.toString()+"-"+stuNo+"-"+clazz;
	}
	@Override
	public boolean equals(Object obj) 
	{
		if (this == obj)
			return true;
		if (getClass() != obj.getClass())
			return false;
		if (!super.equals(obj))
			return false;
		Student other = (Student) obj;
		if (clazz.equals(other.clazz) && stuNo.equals(other.stuNo))
			return true;
		return false;
	}
}

class Company
{
	private String name;
	public Company(String name) 
	{
		if (name == null)
			this.name=null;
		else
			this.name = name;
	}
	@Override
	public String toString() 
	{
		return name;
	}
	@Override
	public boolean equals(Object obj) 
	{
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Company other = (Company) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}	
}

class Employee extends Person{
	private Company company;
	private double salary;
	public Employee(String name, int age, boolean gender, double salary ,Company company) 
	{
		super(name, age, gender);
		this.company = company;
		this.salary = salary;
	}
	@Override
	public String toString() 
	{
		return "Employee:"+super.toString()+"-"+company+"-"+salary;
	}
	@Override
	public boolean equals(Object obj) 
	{
		if (this == obj)
			return true;
		if (getClass() != obj.getClass())
			return false;
		if (!super.equals(obj))
			return false;
		Employee other = (Employee) obj;
		DecimalFormat df = new DecimalFormat("#.#");
		if (company.equals(other.company) && df.format(salary).equals(df.format(other.salary)))
			return true;
		return false;
	}
}

